home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93c.txt
/
000123_icon-group-sender _Wed Dec 15 20:29:55 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1994-02-02
|
2KB
Received: by cheltenham.cs.arizona.edu; Thu, 16 Dec 1993 08:33:58 MST
Date: Wed, 15 Dec 93 20:29:55 pst
From: balexander@ccmail.com
Message-Id: <9311157560.AA756016195@smtpgate.ccmail.com>
To: icon-group@cs.arizona.edu
Subject: Re[2]: Need help with (simple?) programming problem.
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
I first sent my hack at this problem only to Mr. Guilmette, but I decided to
post it to the 'group since the result turned out especially "cute". I'm not
sure this terse solution is quite what he was looking for, but it is kind of
interesting (and shorter than Ken Walker's :-) a notable achievement since
Ken is a truly top-notch Icon programmer). Another example of one of my
favorite Icon techniques: recursive generation (or generative recursion?).
procedure main()
every write(image(gen(["red ", "green ", "blue "])))
end
procedure gen(strings, s, i)
/s := "" & i := 1
if i > *strings then return s
else every (t := ("" | !strings)) & (not find(t, "" ~== s)) do
suspend gen(strings, s || t, i + 1)
end
_______________________________________________________________________________
> From Ronal F. Guilmette:
>
> Assume that I have three strings, i.e. "red ", "green ", and "blue ". Now
> I want to create a generator which will successively yield each unique
> string which contains no more than one instance of each of the original
> strings. Here are the string values which should be yielded by the various
> invocations/resumptions of the generator:
>
> ""
> "red "
> "green "
> "blue "
> "red green "
> "red blue "
> "green red "
> "green blue "
> "blue red "
> "blue green "
> "red green blue "
> "red blue green "
> "green red blue "
> "green blue red "
> "blue red green "
> "blue green red "